package sing.core.util

import java.util.regex.Matcher
import java.util.regex.Pattern

object Utils {

    // @{昵称|id}
    const val regexFriend = "@\\[[^\\]]+]"

    /**
     * 获取所有满足正则表达式的字符串
     * @param str 需要被获取的字符串
     * @param regex 正则表达式
     * @return 所有满足正则表达式的字符串
     */
    fun getAllSatisfyStr(str: String?, regex: String?): ArrayList<String> {
        if (str == null || str.isEmpty()) {
            return ArrayList()
        }
        val allSatisfyStr: ArrayList<String> = ArrayList()
        if (regex == null || regex.isEmpty()) {
            allSatisfyStr.add(str)
            return allSatisfyStr
        }
        val pattern = Pattern.compile(regex)
        val matcher: Matcher = pattern.matcher(str)
        while (matcher.find()) {
            allSatisfyStr.add(matcher.group())
        }
        return allSatisfyStr
    }



}